/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 package com.googlecode.milib.display.button.views {
	import com.googlecode.milib.base.MLBaseClass;

	/**
	 * @author Marek Brun
	 */
	public class AbstractButtonView extends MLBaseClass {
		
		protected var state:Object;		public static const state_OUT:Object={name:'out'};
		public static const state_OVER:Object={name:'over'};
		public static const state_PRESSED:Object={name:'pressed'};
		public static const state_DISABLED:Object={name:'disabled'};		
		private var isFreez:Boolean;		
		private var lastRequestedState:Object;
		
		public function AbstractButtonView() {
			isFreez=false;
		}
		/*abstract*/ protected function doCurrentState():void {}
		
		public function setState(AbstractButtonView_state_:Object):void {
			if(isFreez){
				lastRequestedState=AbstractButtonView_state_;
				return;
			}
			if(AbstractButtonView_state_==state){ return; }
			state=AbstractButtonView_state_;
			doCurrentState();
		}
		
		public function setIsFreez(freez:Boolean):void {
			if(isFreez==freez){ return; }
			isFreez=freez;
			if(!freez && lastRequestedState){
				setState(lastRequestedState);
				lastRequestedState=null;
			}
		}
		
	}
}